package com.zcr.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zcr.mapper.StoreMapper;
import com.zcr.pojo.Store;
import com.zcr.service.StoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service("StoreServiceimpl")
public class StoreServiceimpl extends ServiceImpl<StoreMapper, Store> implements StoreService {

    @Resource
    private StoreMapper storeMapper;

    @Override
    public IPage<Store> searchAll(String drugname, Page<Store> storePage) {
        QueryWrapper<Store> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isBlank(drugname),"drugname",drugname);
        storePage=storeMapper.selectPage(storePage,queryWrapper);
        return storePage;
    }

    @Override
    public void updateStore(Store store) {
        storeMapper.updateById(store);

    }

    @Override
    public void deleteStore(Store store) {
        storeMapper.deleteById(store.getId());
    }

    @Override
    public void deleteAllStore(String[] ids) {
        storeMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public boolean add(Store store) {
        return storeMapper.insert(store)>0;
    }

    @Override
    public boolean update(Store store) {
        return storeMapper.updateById(store)>0;
    }

    @Override
    public List<Store> quehuolist(int count) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("count",count);
        return storeMapper.selectList(wrapper);
    }

    @Override
    public List<Store> kucunyujinglist(Integer count) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.le(!StringUtils.isBlank(String.valueOf(count)),"count",count);
        return storeMapper.selectList(wrapper);
    }

}
